package com.springcloudalibaba.serviceJournal.controller;

import com.springcloudalibaba.bclass.base.BasePageResult;
import com.springcloudalibaba.bclass.base.BaseResult;
import com.springcloudalibaba.serviceJournal.entity.MsgEntity;
import com.springcloudalibaba.serviceJournal.service.MsgService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  短信 前端控制器
 * </p>
 *
 * @author lixing_java@163.com
 * @since 2021-06-06
 */
@RestController
@RequestMapping("/msg")
public class MsgController {
    @Resource
    private MsgService msgService;

    /*
     * @描述 TODO [短信]分页列表
     * @作者 lixing
     * @日期 2019/2/16 13:08
     */
    @PostMapping("pageMsg")
    public BasePageResult<MsgEntity> pageMsg(@RequestBody MsgEntity entity) {
//        Page<BaseMsgEntity> page = msgService.page(new Page<>(entity.basePageNum, entity.basePageSize), queryWrapperForEMsg(entity));
//        return new BasePageResult<>(page);
        return null;
    }

    /*
     * @描述 TODO [短信]列表
     * @作者 lixing
     * @日期 2019/9/11 9:14
     */
    @PostMapping("listMsg")
    public BaseResult<List<MsgEntity>> listMsg(@RequestBody MsgEntity entity) {
//        List<BaseMsgEntity> msgEntityList = msgService.list(queryWrapperForEMsg(entity));
//        return new BaseResult<List<BaseMsgEntity>>().success(msgEntityList);
        return null;
    }

    /*
     * @描述 TODO [短信]添加
     * @作者 lixing
     * @日期 2019/2/16 13:08
     */
    @PostMapping("insertMsg")
    public BaseResult<String> insertMsg(@RequestBody MsgEntity entity) throws Exception {
//        CompletableFuture<BaseResult<String>> sendMsgCompletableFuture = MsgService.sendHtmlMsg(entity);
//        CompletableFuture.allOf(sendMsgCompletableFuture).join();
//        return sendMsgCompletableFuture.get();
        return null;
    }

    /*
     * @描述 TODO [短信]删除
     * @作者 lixing
     * @日期 2019/9/11 9:14
     */
    @PostMapping("deleteMsg")
    public BaseResult<Boolean> deleteMsg(@RequestBody MsgEntity entity) {
        boolean flag;
        if (!entity.getBaseLongList().isEmpty()) {
            flag = msgService.removeByIds(entity.getBaseLongList());
        } else if (null != entity.getId()) {
            flag = msgService.removeById(entity.getId());
        } else {
            return new BaseResult<Boolean>().fail("主键缺失");
        }
        return flag ? new BaseResult<Boolean>().success() : new BaseResult<Boolean>().fail();
    }

    /*
     * @描述 TODO [短信]详情
     * @作者 lixing
     * @日期 2019/9/11 9:14
     */
    @PostMapping("detailMsg")
    public BaseResult<MsgEntity> detailMsg(@RequestBody MsgEntity entity) {
        entity = msgService.getById(entity.getId());
        return new BaseResult<MsgEntity>().success(entity);
    }
}

